﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>骏怡连锁酒店后台管理-用户管理</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="assets/materialize/css/materialize.min.css" media="screen,projection" />
    <!-- Bootstrap Styles-->
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
    <!-- FontAwesome Styles-->
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
    <!-- Morris Chart Styles-->
    <link href="assets/js/morris/morris-0.4.3.min.css" rel="stylesheet" />
    <!-- Custom Styles-->
    <link href="assets/css/custom-styles.css" rel="stylesheet" />
    <!-- Google Fonts-->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
    <link rel="stylesheet" href="assets/js/Lightweight-Chart/cssCharts.css">
    <!-- Sweet Alert-->
    <link rel="stylesheet" href="assets/css/sweetalert2.min.css">
    <style>
        th {
            text-align: center;
        }

        #btnzmx {
            margin-bottom: 20px;
            float: right;
        }
    </style>
</head>

<body>
    <div id="wrapper">
        <nav class="navbar navbar-default top-navbar" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle waves-effect waves-dark" data-toggle="collapse" data-target=".sidebar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand waves-effect waves-dark" href="index.html">
                    <i class="large material-icons">track_changes</i>
                    <strong>Hotel Manage</strong>
                </a>

                <div id="sideNav" href="">
                    <i class="material-icons dp48">toc</i>
                </div>
            </div>

            <ul class="nav navbar-top-links navbar-right">
                <li>
                    <a class="dropdown-button waves-effect waves-dark" href="#!" data-activates="dropdown1">
                        <i class="fa fa-user fa-fw"></i>
                        <b id='admin'></b>
                        <i class="material-icons right">arrow_drop_down</i>
                    </a>
                </li>
            </ul>
        </nav>
        <!-- Dropdown Structure -->
        <ul id="dropdown1" class="dropdown-content">
            <li>
                <a href="#">
                    <i class="fa fa-user fa-fw"></i> 个人中心</a>
            </li>
            <li>
                <a href="#">
                    <i class="fa fa-gear fa-fw"></i> 设置</a>
            </li>
            <li id='logoutBtn'>
                <a href="#">
                    <i class="fa fa-sign-out fa-fw"></i> 退出登录</a>
            </li>
        </ul>
        <!--/. NAV TOP  -->
        <!--/. NAV TOP  -->
        <nav class="navbar-default navbar-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav" id="main-menu">
                    <li>
                        <a class="waves-effect waves-dark" href="index.html">
                            <i class="fa fa-dashboard"></i> 首页</a>
                    </li>
                    <li>
                        <a href="employee.html" class="waves-effect waves-dark">
                            <i class="fa fa-desktop"></i> 员工管理</a>
                    </li>
                    <li>
                        <a href="room.html" class="waves-effect waves-dark">
                            <i class="fa fa-bar-chart-o"></i> 客房管理</a>
                    </li>
                    <li>
                        <a href="role.html" class="waves-effect waves-dark">
                            <i class="fa fa-qrcode"></i>角色管理</a>
                    </li>

                    <li>
                        <a href="user.html" class="active-menu waves-effect waves-dark">
                            <i class="fa fa-table"></i>用户管理</a>
                    </li>
                </ul>

            </div>

        </nav>
        <!-- /. NAV SIDE  -->
        <div id="page-wrapper">
            <div class="header">
                <h1 class="page-header">
                    用户管理
                </h1>
                <ol class="breadcrumb">
                    <li>
                        <a href="#">主页</a>
                    </li>
                    <li>
                        <a href="#">用户管理</a>
                    </li>
                    <li class="active">数据</li>
                </ol>

            </div>
            <div id="page-inner">
                <div id="btnzmx">
                    <a href="addUser.html" class="btn btn-info">添加用户</a>
                </div>
                <table class="table table-striped  table-bordered  table-hover" style="background: white;">
                    <tr>
                        <th style="background-color:#ccc">编号</th>
                        <th style="background-color:#ccc">姓名</th>
                        <th style="background-color:#ccc">电话</th>
                        <th style="background-color:#ccc">状态</th>
                        <th style="background-color:#ccc">操作</th>
                    </tr>

                </table>
            </div>

            <!-- /. ROW  -->
        </div>
        <!-- /. PAGE INNER  -->
    </div>
    <!-- /. PAGE WRAPPER  -->
    <!-- /. WRAPPER  -->
    <!-- JS Scripts-->

    <!-- jQuery Js -->
    <script src="assets/js/jquery-1.10.2.js"></script>

    <!-- Bootstrap Js -->
    <script src="assets/js/bootstrap.min.js"></script>

    <script src="assets/materialize/js/materialize.min.js"></script>

    <!-- Metis Menu Js -->
    <script src="assets/js/jquery.metisMenu.js"></script>
    <!-- Morris Chart Js -->
    <script src="assets/js/morris/raphael-2.1.0.min.js"></script>
    <script src="assets/js/morris/morris.js"></script>


    <script src="assets/js/easypiechart.js"></script>
    <script src="assets/js/easypiechart-data.js"></script>

    <script src="assets/js/Lightweight-Chart/jquery.chart.js"></script>
    <!-- DATA TABLE SCRIPTS -->
    <script src="assets/js/dataTables/jquery.dataTables.js"></script>
    <script src="assets/js/dataTables/dataTables.bootstrap.js"></script>
    <!-- Sweet Alert -->
    <script src="assets/js/sweetalert2.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#dataTables-example').dataTable();
        });


        $.ajax({
            url: 'users',
            method: "GET",
            success: function (data) {
                $.each(data, function (index, value) {
                    var state = value.state == 1 ? '冻结' : '解冻';
                    var str =
                        `<button type="button" class="btn btn-danger state" state='${value.state}'>${state}</button>`;
                    $(
                        `<tr>
                       <th>${value. id}</th>
                       <th>${value. username}</th>
                       <th>${value. phone}</th>
                       <th>${value.state==1?'正常':'冻结'}</th>
                       <th>
                        <button type="button" class="btn btn-info resetPassword" id="${value.id}">重置密码</button>
                        ${str}
                        </th>
                        </tr>`
                    ).appendTo('table');
                })
            }
        })


        $(document).on('click', '.resetPassword', function () {
            var id = this.id;
            swal({
                title: '请输入新密码',
                input: 'password',
                showCancelButton: true,
                inputValidator: function (value) {
                    // ajax
                    $.ajax({
                        url: 'resetPassword',
                        method: "POST",
                        data: `id=${id}&password=${value}`,
                        success: function (data) {
                            if (data == 'success') {
                                swal('操作成功', '重置密码成功', 'success');
                            }
                        }
                    })
                }
            })
        })

        $(document).on('click', '.state', function (e) {
            var txt = e.target.getAttribute('state') == 1 ? '冻结' : '解冻';
            var id = $(this).parents('tr').children('th:first').html();
            swal({
                type: 'warning',
                title: '您确定要' + txt + '该用户吗?',
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                showLoaderOnConfirm: true,
                preConfirm: function () {
                    return new Promise(function (resolve) {
                        $.ajax({
                            url: 'changeUserState',
                            method: "POST",
                            data: `id=${id}&state=${e.target.getAttribute('state') == 1?0:1}`,
                            success: function (data) {
                                if (data == 'success') {
                                    location.reload();
                                }
                            }
                        })
                    });
                },
                allowOutsideClick: false
            }).then(function (email) {
                if (email) {
                    swal({
                        type: 'success',
                        title: 'Ajax request finished!',
                        html: 'Submitted email: ' + email
                    });
                }
            })
        })
    </script>
    <!-- Custom Js -->
    <script src="assets/js/custom-scripts.js"></script>
    <script src="assets/js/public.js"></script>

</body>

</html>